<template>
  <div v-if="result" class="items">
    <!--单选题-->
        <el-radio-group v-model="result.itemRId" v-if="type=='0'" :disabled = "optionsDisabled">
          <el-radio v-for="item in options" :label="item.itemRId">{{item.name}} </el-radio>
          <el-radio v-show="other" :label="12" >其他</el-radio>
        </el-radio-group>
    <!--多选题-->
        <el-checkbox-group v-model="result.itemRList" v-else-if="type=='1'" >
          <el-checkbox v-for="item in options" :label="item.itemRId" :disabled = "optionsDisabled">{{item.name}}</el-checkbox>
        </el-checkbox-group>
    <!--填空题-->
        <el-input v-else-if="type=='2'"
                  type="textarea"
                  :rows="3"
                  :disabled = "optionsDisabled"
                  placeholder="请输入内容"
                  v-model="result.text" >
        </el-input>
  </div>
</template>

<script>
  export default {
    props:["options","type","other","itemId","setId","optionsDisabled"],
    data(){
      return{
        picked: '',
        picked2: '',
        isResultShow:false,
        currentItemId:0,
        result:{
          itemId:0,
          itemRId:0,
          itemRList: [],
          setId:0,
          text:"",
          type:0,
        },
      }
    },
    methods: {
      init(){
        console.log( "optionsDisabled="+this.optionsDisabled);
        let self = this;
        this.options.forEach(function (item) {
          if(self.type == '0' ){
            if(item.check == 1){
              self.result.itemRId = item.itemRId;
            }
          }else if(self.type == '1'){
            if(item.check == 1){
              self.result.itemRList.push(item.itemRId);
            }
          }else if(self.type == '2'){
            if(item.check == 1) {
              self.result.text = item.name;
            }
          }
        });
      },
      isResult(){
       this.isResultShow = true;
      }
    },
    watch:{
      result:{
        handler(val){
          this.result.itemId = this.itemId;
          this.result.setId = this.setId;
          this.result.type = this.type;
          this.$emit("updateOption",this.result);
        },
        deep:true
      }
    },
    mounted: function () {
      this.init();

    }
  }
</script>

<style>

   .options{
    padding-left: 15px;
    font-size: 14px!important;
  }
   .options label{
    display: block;
  }
   .options .el-radio+.el-radio{
    margin: 12px 0px!important;
  }
   /*.options>.el-radio-group>.el-radio>span.el-radio__input{*/
     /*display: none!important;*/
   /*}*/
</style>
